package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SlPostn;
import com.ruoyi.sl.service.ISlPostnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位Controller
 * 
 * @author admin
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/sl/postn")
public class SlPostnController extends BaseController
{
    @Autowired
    private ISlPostnService slPostnService;

    /**
     * 查询岗位列表
     */
    @PreAuthorize("@ss.hasPermi('sl:postn:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlPostn slPostn)
    {
        startPage();
        List<SlPostn> list = slPostnService.selectSlPostnList(slPostn);
        return getDataTable(list);
    }

    /**
     * 导出岗位列表
     */
    @PreAuthorize("@ss.hasPermi('sl:postn:export')")
    @Log(title = "岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlPostn slPostn)
    {
        List<SlPostn> list = slPostnService.selectSlPostnList(slPostn);
        ExcelUtil<SlPostn> util = new ExcelUtil<SlPostn>(SlPostn.class);
        util.exportExcel(response, list, "岗位数据");
    }

    /**
     * 获取岗位详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:postn:query')")
    @GetMapping(value = "/{postnId}")
    public AjaxResult getInfo(@PathVariable("postnId") Long postnId)
    {
        return success(slPostnService.selectSlPostnByPostnId(postnId));
    }

    /**
     * 新增岗位
     */
    @PreAuthorize("@ss.hasPermi('sl:postn:add')")
    @Log(title = "岗位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlPostn slPostn)
    {
        return toAjax(slPostnService.insertSlPostn(slPostn));
    }

    /**
     * 修改岗位
     */
    @PreAuthorize("@ss.hasPermi('sl:postn:edit')")
    @Log(title = "岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlPostn slPostn)
    {
        return toAjax(slPostnService.updateSlPostn(slPostn));
    }

    /**
     * 删除岗位
     */
    @PreAuthorize("@ss.hasPermi('sl:postn:remove')")
    @Log(title = "岗位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postnIds}")
    public AjaxResult remove(@PathVariable Long[] postnIds)
    {
        return toAjax(slPostnService.deleteSlPostnByPostnIds(postnIds));
    }
}
